package com.xinggq.user.service.controller.feign;

import com.xinggq.common.CommonResult;
import com.xinggq.user.api.dto.UserInfoDTO;
import com.xinggq.user.api.feign.UserInfoApi;
import com.xinggq.user.service.entity.SysUserEntity;
import com.xinggq.user.service.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author xinggq
 * @Date 2025/10/30
 */
@Slf4j
@RestController
@RequestMapping("/api/user/info")
@RequiredArgsConstructor
@Tag(name = "用户信息API", description = "提供用户信息相关接口")
public class UserInfoController implements UserInfoApi {

  private final UserInfoService userInfoService;

  @Override
  @GetMapping("/{userId}")
  @Operation(summary = "获取用户信息", description = "根据用户ID获取用户信息")
  public CommonResult<UserInfoDTO> getUserById(Long userId) {
    log.info("接收到获取用户信息的请求: {}", userId);
    SysUserEntity userEntity = userInfoService.getUserById(userId);
    return userEntity != null ? CommonResult.ok(userEntity.toUserInfoDTO())
        : CommonResult.ok(null);
  }

}
